<template>
  <d2-container>
    <div slot="header">
      <!-- 搜索框 -->
      <el-input
        v-model="tablePages.departmentId"
        placeholder="请输入内容"
        class="inputBox"
      ></el-input>
      <el-button type="button" class="botton_souch" @click="searchTableData" >搜索 </el-button>

       <!-- 选择器 -->
    <el-select v-model="value" clearable placeholder="请选择" class="selector">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    </div>

     <!-- table -->
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"> </el-table-column>

        <el-table-column prop="dept" label="部门" width="80">
          <template slot-scope="scope">{{ scope.row.appraisalTemplate.department }}</template>
        </el-table-column>
        <el-table-column prop="ifpa_name" label="考核名称" width="120">
          <template slot-scope="scope">{{ scope.row.appraisalTemplate.templateName }}</template>
        </el-table-column>
        <el-table-column prop="type" label="考核类型" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.appraisalTemplate.type }}</template>
        </el-table-column>
        <el-table-column prop="type" label="被考核人" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column prop="type" label="创建日期" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.createTime }}</template>
        </el-table-column>
        <el-table-column prop="type" label="考核人" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.templateId }}</template>
        </el-table-column>
        <el-table-column prop="type" label="考核得分" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.score }}</template>
        </el-table-column>
        <el-table-column prop="type" label="考核状态" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.status }}</template>
        </el-table-column>
      </el-table>
     <!-- 分页 -->
      <div class="block">
        <span class="demonstration"></span>
        <!--
          :current-page 当前页数
          :page-size 每页条数
          :total 总共条数
         -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="tablePages.currentPage"
          :page-size="tablePages.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tablePages.total"
        >
        </el-pagination>
      </div>
    </d2-container >
</template>

<script>
// export default {
//   name: 'page1'
// }
//
</script>

<style>
.block {
  float: right;
}

.inputBox {
  width: 25%;
}

.botton_souch {
  margin-left: 2%;
}

.selector{
  margin-left: 5%;
}
</style>

// 组件js
<script>
export default {
  data() {
    return {
      //搜索框
      input: "",

      // 选择器
       options: [{
          value: '选项1',
          label: '黄金糕'
        }, {
          value: '选项2',
          label: '双皮奶'
        }, {
          value: '选项3',
          label: '蚵仔煎'
        }, {
          value: '选项4',
          label: '龙须面'
        }, {
          value: '选项5',
          label: '北京烤鸭'
        }],
        value: '',

      // table
      tableData: [
      ],
      multipleSelection: [],
         // 配置表格信息
      tablePages: {
        // 当前页数
        currentPage: 1,
        // 每页条数
        limit: 10,
        // 列表总数
        total: 0,
        // 搜索框
        departmentId: ''
      }
    };
  },
  created() {
    this.getTableList(this.tablePages);
     },
  methods: {
     // 查找所有
    getTableList({ currentPage, limit, departmentId }) {
      this.$request({
        url: "examineList/findExamineListFormInline",
        method: "post",
        data: {
          currentPage,
          limit,
         departmentId
        },
      }).then((res) => {
        // 给表格赋值
        this.tableData = res.list;
        // 给表格总数赋值
        this.tablePages.total = res.total;
      });
    },
    /**
     * 页码发生改变时触发的事件
     * @date 2021-12-16
     * @param {any} currentPage 切换后的当前页码
     */
    handleCurrentChange (currentPage) {
      this.tablePages.currentPage = currentPage
      this.getTableList(this.tablePages)
    },
    /**
     * 页数发生改变时触发的事件
     * @date 2021-12-16
     * @param {any} limit 切换后的每页条数
     */
    handleSizeChange (limit) {
      this.tablePages.limit = limit
      this.getTableList(this.tablePages)
    },
     // 搜索
    searchTableData () {
      console.log(this.tablePages.departmentId)
      this.getTableList(this.tablePages, this.tablePages.departmentId)
      this.tablePages.departmentId = null
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>
